Skip to content

hostgroup nonadmin viewer read - #20875

Merged
pondrejk merged 1 commit into
SatelliteQE:masterfrom
pnovotny:hostgroup-nonadmin-viewer
Feb 26, 2026
Merged

hostgroup nonadmin viewer read#20875
pondrejk merged 1 commit into
SatelliteQE:masterfrom
pnovotny:hostgroup-nonadmin-viewer

Conversation

@pnovotny

@pnovotny pnovotny commented Feb 25, 2026

Copy link
Copy Markdown
Contributor

Problem Statement

New test coverage for bug SAT-38451: Non-admin users on Satellite with viewer role, unable to see the hostgroup.

Solution

Ensure that non-admin user with viewer role can see hostgroup created by admin user.

Also added new UserFactory class to help with more reusable user fixtures.

PRT

trigger: test-robottelo
pytest: tests/foreman/ui/test_hostgroup.py -k test_positive_non_admin_viewer_role_read

Summary by Sourcery

Add test coverage to ensure non-admin users with Viewer role can see host groups created by admin users and introduce reusable user and host group fixtures to support this scenario.

New Features:

  • Introduce a UserFactory helper for reusable user creation in fixtures.
  • Add fixtures for a non-admin Viewer-role user and a host group tied to specific organization and location.

Tests:

  • Add UI test verifying a non-admin user with Viewer role can view host groups created by an admin user.

Verifies: SAT-38451

New test for bug "Non-admin users on Satellite with viewer role, unable to see the hostgroup."
Ensure that non-admin user with viewer role can see hostgroup created by admin user.

Also added new `UserFactory` class to help with more reusable user fixtures.
@pnovotny pnovotny added CherryPick PR needs CherryPick to previous branches AutoMerge_Cherry_Picked The cherrypicked PRs of master PR would be automerged if all checks passing Stream Introduced in or relating directly to Satellite Stream/Master 6.18.z Introduced in or relating directly to Satellite 6.18 6.19.z labels Feb 25, 2026
@pnovotny pnovotny self-assigned this Feb 25, 2026
@pnovotny
pnovotny requested a review from a team February 25, 2026 17:29
@sourcery-ai

sourcery-ai Bot commented Feb 25, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Add a UI test ensuring a non-admin user with the Viewer role can see an admin-created host group, and introduce reusable user/hostgroup fixtures including a UserFactory helper and a host group fixture bound to org/location.

Sequence diagram for non-admin Viewer user reading admin-created hostgroup

sequenceDiagram
    actor Admin
    actor Viewer
    participant Test as TestCase
    participant SatAPI as Satellite_API
    participant SatUI as Satellite_UI

    Test->>SatAPI: create_hostgroup_with_org_loc()
    SatAPI-->>Test: hostgroup

    Test->>SatAPI: UserFactory.create_user(admin=False, role=Viewer)
    SatAPI-->>Test: viewer_user

    Viewer->>SatUI: login(username, password)
    SatUI-->>Viewer: dashboard

    Viewer->>SatUI: navigate_to_hostgroups()
    SatUI->>SatAPI: list_hostgroups_for_user(viewer_user)
    SatAPI-->>SatUI: hostgroups_in_org_and_location
    SatUI-->>Viewer: display_hostgroup_list(includes_admin_created)

    Test-->>Test: assert hostgroup is visible to viewer_user
Loading

ER diagram for user, role, hostgroup, org, and location relationships

erDiagram
    USER ||--o{ ROLE : has
    USER }o--|| ORGANIZATION : belongs_to
    USER }o--|| LOCATION : scoped_to

    HOSTGROUP }o--|| ORGANIZATION : scoped_to
    HOSTGROUP }o--|| LOCATION : scoped_to

    ROLE {
        string name
    }
    USER {
        string username
        string password
        boolean admin
    }
    ORGANIZATION {
        string name
    }
    LOCATION {
        string name
    }
    HOSTGROUP {
        string name
    }
Loading

Class diagram for the new UserFactory helper

classDiagram
    class UserFactory {
        +create_user(target_sat, params)
    }

    class Satellite {
    }

    class User {
        +password
    }

    UserFactory ..> Satellite : uses
    UserFactory ..> User : creates
Loading

File-Level Changes

Change Details Files
Introduce a reusable UserFactory helper and viewer-role fixtures for creating non-admin viewer users.
  • Add UserFactory class with a static create_user method that ensures a password is set, creates the user via the Satellite API, and stores the generated password on the user object.
  • Add a session-scoped viewer_role fixture that looks up the existing Viewer role from the Satellite API.
  • Refactor default_viewer_role fixture to use UserFactory.create_user instead of in-line user creation and password generation, and to depend on the shared viewer_role fixture.
  • Add a module_user_viewer fixture that creates a non-admin user with Viewer role bound to the module’s organization and location using UserFactory.create_user.
pytest_fixtures/component/user_role.py
Add a hostgroup fixture associated with specific organization and location to support cross-user visibility tests.
  • Introduce module_hostgroup_with_org_loc fixture that creates a HostGroup bound to the module’s organization and location via the Satellite API.
pytest_fixtures/component/hostgroup.py
Add a UI test validating that a non-admin user with Viewer role can see an admin-created host group.
  • Introduce test_positive_non_admin_viewer_role_read that logs in as a non-admin Viewer user, selects the correct organization and location, and verifies the presence of the admin-created host group in the UI hostgroup list.
  • Use the module_user_viewer and module_hostgroup_with_org_loc fixtures to set up the user and hostgroup for the test.
tests/foreman/ui/test_hostgroup.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@pnovotny

Copy link
Copy Markdown
Contributor Author

trigger: test-robottelo
pytest: tests/foreman/ui/test_hostgroup.py -k test_positive_non_admin_viewer_role_read

@Satellite-QE

Copy link
Copy Markdown
Collaborator

PRT Result

Build Number: 14482
Build Status: SUCCESS
PRT Comment: pytest tests/foreman/ui/test_hostgroup.py -k test_positive_non_admin_viewer_role_read --external-logging
Test Result : =========== 1 passed, 7 deselected, 8 warnings in 807.55s (0:13:27) ============

@Satellite-QE Satellite-QE added the PRT-Passed Indicates that latest PRT run is passed for the PR label Feb 25, 2026
@pnovotny
pnovotny marked this pull request as ready for review February 25, 2026 17:55
@pnovotny
pnovotny requested a review from a team as a code owner February 25, 2026 17:55

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@pnovotny
pnovotny requested a review from a team February 25, 2026 18:30
@pondrejk
pondrejk merged commit 0da20ab into SatelliteQE:master Feb 26, 2026
16 checks passed
github-actions Bot pushed a commit that referenced this pull request Feb 26, 2026
hostgroups: new test for non-admin viewer role

Verifies: SAT-38451

New test for bug "Non-admin users on Satellite with viewer role, unable to see the hostgroup."
Ensure that non-admin user with viewer role can see hostgroup created by admin user.

Also added new `UserFactory` class to help with more reusable user fixtures.

(cherry picked from commit 0da20ab)
github-actions Bot pushed a commit that referenced this pull request Feb 26, 2026
hostgroups: new test for non-admin viewer role

Verifies: SAT-38451

New test for bug "Non-admin users on Satellite with viewer role, unable to see the hostgroup."
Ensure that non-admin user with viewer role can see hostgroup created by admin user.

Also added new `UserFactory` class to help with more reusable user fixtures.

(cherry picked from commit 0da20ab)
@pnovotny
pnovotny deleted the hostgroup-nonadmin-viewer branch February 27, 2026 09:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.18.z Introduced in or relating directly to Satellite 6.18 6.19.z AutoMerge_Cherry_Picked The cherrypicked PRs of master PR would be automerged if all checks passing CherryPick PR needs CherryPick to previous branches PRT-Passed Indicates that latest PRT run is passed for the PR Stream Introduced in or relating directly to Satellite Stream/Master

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants